
<template>
  <BaseDialog
    title="主类别信息"
    v-model:visible="innerVisible"
    :renderDefaultFooter="false"
    width="500px"
  >
    <MyForm
      :save-btn-loading="subLoading"
      v-model:formData="formData"
      v-model:columns="column"
      :labelWidth="120"
      background="#fff"
      :rules="rule"
      @submit="saveFormdata"
      @cancel="innerVisible = false"
    />
  </BaseDialog>
</template>
<script  setup>
import { ref, watch, computed } from "vue";
import * as api from "@/api/index";
const props = defineProps({
  editData: {
    type: Object,
    default: null,
  },
  visible: {
    type: Boolean,
  },
});
const innerVisible = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emit("update:visible", val);
  },
});
const subLoading = ref(false);
let formData = ref({});
const editData = props.editData;
const column = [
  {
    title: "",
    structure: [
      {
        content: [
          {
            x: 0,
            y: 1,
            w: 24,
            h: 1,
            i: "1",
            label: "主类别名称（中）",
            prop: "mainName",
            type: "label_input",
            maxlength: 200,
            span: 24,
          },
          {
            x: 0,
            y: 2,
            w: 24,
            h: 1,
            i: "2",
            label: "主类别名称（英）",
            prop: "mainNameEn",
            type: "label_input",
            maxlength: 200,
            span: 24,
          },
        ],
      },
    ],
  },
];
const rule = ref({
  mainName: {
    required: true,
    message: "请输入主类别名称（中）",
    trigger: ["blur", "change"],
  },
  mainNameEn: {
    required: true,
    message: "主类别名称（英）",
    trigger: ["blur", "change"],
  },
  mainNameAr: {
    required: true,
    message: "主类别名称（泰）",
    trigger: ["blur", "change"],
  },
});
const emit = defineEmits(["update:visible", "handleSuccess"]);
async function saveFormdata() {
  subLoading.value = true;
  try {
    await api.default.system.dictionaryData.addEditMain(formData.value);
    ElMessage.success("保存成功");
    subLoading.value = false;
    emit("handleSuccess");
    innerVisible.value = false;
  } catch {
    subLoading.value = false;
  }
}
onMounted(() => {
  formData.value = { ...editData } || {};
});
</script>
